package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CartController {

    @Autowired
    private CartService cartService;
    //添加菜品或套餐
    @PostMapping("/cart/add")
    public ResultInfo cartAdd(@RequestBody Cart cart){
        Cart cart1 = cartService.cartAdd(cart);
        return ResultInfo.success(cart1);
    }
    //获取购物车数据
    @GetMapping("/cart/list")
    public ResultInfo cartList(){
        List<Cart> cartList = cartService.cartList();
        return ResultInfo.success(cartList);
    }

    //减少菜品或套餐
    @PostMapping("/cart/sub")
    public ResultInfo cartSub(@RequestBody Cart cart) {
        Cart cart1 = cartService.cartSub(cart);
        return ResultInfo.success(cart1);
    }
    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo cartClean(){
        cartService.cartClean();
        return ResultInfo.success(null);
    }

}
